#include "mainwindow.h"
#include "ui_mainwindow.h"

#include "dialog.h"

#include <QPainter>

float y_list[] = {
	-2.909513,
	-2.889908,
	-2.875877,
	-2.859,
	-2.839272,
	-2.82232,
	-2.80533,
	-2.788305,
	-2.771245,
	-2.751295,
	-2.734156,
	-2.716978,
	-2.696894,
	-2.676755,
	-2.656572,
	-2.63634,
	-2.618954,
	-2.598627,
	-2.581166,
	-2.560745,
	-2.540274,
	-2.519758,
	-2.499188,
	-2.478568,
	-2.460854,
	-2.440144,
	-2.41938,
	-2.39857,
	-2.377706,
	-2.356796,
	-2.338832,
	-2.317828,
	-2.296769,
	-2.275664,
	-2.257535,
	-2.236336,
	-2.218122,
	-2.196832,
	-2.178538,
	-2.157152,
	-2.141848,
	-2.123444,
	-2.108084,
	-2.089609,
	-2.074189,
	-2.058744,
	-2.043274,
	-2.03088,
	-2.015359,
	-2.002925,
	-1.993591,
	-1.981127,
	-1.97489,
	-1.96553,
	-1.959283,
	-1.95303,
	-1.949904,
	-1.946773,
	-1.946773,
	-1.946773,
	-1.949904,
	-1.95303,
	-1.962404,
	-1.968652,
	-1.981127,
	-1.990476,
	-2.009147,
	-2.024673,
	-2.043274,
	-2.061835,
	-2.086528,
	-2.111155,
	-2.138783,
	-2.166325,
	-2.199877,
	-2.2333,
	-2.269623,
	-2.30279,
	-2.338832,
	-2.374725,
	-2.41938,
	-2.460854,
	-2.502129,
	-2.543205,
	-2.586988,
	-2.630548,
	-2.673874,
	-2.719844,
	-2.762701,
	-2.80533,
	-2.853371,
	-2.901116,
	-2.943007,
	-2.98467,
	-3.037116,
	-3.086465,
	-3.127344,
	-3.165294,
	-3.213802,
	-3.259313,
	-3.301886,
	-3.341566,
	-3.383643,
	-3.422861,
	-3.467035,
	-3.510928,
	-3.549414,
	-3.587678,
	-3.630779,
	-3.67108,
	-3.706135,
	-3.741002,
	-3.778143,
	-3.812607,
	-3.846878,
	-3.880958,
	-3.91726,
	-3.950943,
	-3.982044,
	-4.010612,
	-4.041398,
	-4.072017,
	-4.100137,
	-4.130442,
	-4.158271,
	-4.185957,
	-4.213502,
	-4.240909,
	-4.265912,
	-4.288538,
	-4.313314,
	-4.337971,
	-4.360286,
	-4.382507,
	-4.402423,
	-4.422259,
	-4.444206,
	-4.463877,
	-4.485644,
	-4.505146,
	-4.522423,
	-4.53963,
	-4.556781,
	-4.57387,
	-4.588773,
	-4.603625,
	-4.620545,
	-4.635299,
	-4.650005,
	-4.664664,
	-4.677194,
	-4.691764,
	-4.704219,
	-4.716637,
	-4.731081,
	-4.743423,
	-4.755733,
	-4.76801,
	-4.782286,
	-4.794488,
	-4.806653,
	-4.818785,
	-4.828867,
	-4.838926,
	-4.850965,
	-4.860973,
	-4.872952,
	-4.884892,
	-4.894816,
	-4.904721,
	-4.916569,
	-4.926419,
	-4.936244,
	-4.946047,
	-4.955827,
	-4.963631,
	-4.975311,
	-4.985017,
	-4.994699,
	-5.004357,
	-5.012069,
	-5.019766,
	-5.02936,
	-5.037024,
	-5.046576,
	-5.056105,
	-5.063715,
	-5.07131,
	-5.078886,
	-5.086444,
	-5.093993,
	-5.101524,
	-5.10904,
	-5.116543,
	-5.124027,
	-5.129633,
	-5.137094,
	-5.144536,
	-5.151965,
	-5.15753,
	-5.16493,
	-5.172322,
	-5.179691,
	-5.185214,
	-5.192559,
	-5.198059,
	-5.205377,
	-5.210858,
	-5.21633,
	-5.221793,
	-5.22906,
	-5.236318,
	-5.241748,
	-5.247169,
	-5.252586,
	-5.257989,
	-5.263388,
	-5.270572,
	-5.275951,
	-5.281318,
	-5.286679,
	-5.29025,
	-5.297374,
	-5.302712,
	-5.306265,
	-5.311585,
	-5.316896,
	-5.322202,
	-5.325732,
	-5.329262,
	-5.334545,
	-5.339819,
	-5.343335,
	-5.348595,
	-5.352098,
	-5.355599,
	-5.360842,
	-5.36433,
	-5.367814,
	-5.371298,
	-5.374777,
	-5.378252,
	-5.381721,
	-5.385191,
	-5.388652,
	-5.393844,
	-5.395569,
	-5.399021,
	-5.402472,
	-5.405915,
	-5.409358,
	-5.412796,
	-5.416229,
	-5.417941,
	-5.42137,
	-5.423081,
	-5.426506,
	-5.429925,
	-5.43334,
	-5.43675,
	-5.438453,
	-5.441859,
	-5.443562,
	-5.446959,
	-5.450355,
	-5.452053,
	-5.453747,
	-5.457134,
	-5.458828,
	-5.460522,
	-5.4639,
	-5.46559,
	-5.467278,
	-5.470652,
	-5.472337,
	-5.474021,
	-5.475706,
	-5.475706,
	-5.477386,
	-5.47907,
	-5.48075,
	-5.48243,
	-5.48411,
	-5.485785,
	-5.487461,
	-5.487461,
	-5.489141,
	-5.490811,
	-5.490811,
	-5.492487,
	-5.492487,
	-5.494162,
	-5.495833,
	-5.495833,
	-5.495833,
	-5.497504,
	-5.497504,
	-5.497504,
	-5.499175,
	-5.499175,
	-5.499175,
	-5.500845,
	-5.500845,
	-5.500845,
	-5.502512,
	-5.502512,
	-5.504178,
	-5.504178,
	-5.504178,
	-5.504178,
	-5.504178,
	-5.504178,
	-5.505844,
	-5.505844,
	-5.505844,
	-5.505844,
	-5.505844,
	-5.50751,
	-5.50751,
	-5.505844,
	-5.505844,
	-5.505844,
	-5.505844,
	-5.505844,
	-5.505844,
	-5.504178,
	-5.504178,
	-5.504178,
	-5.504178,
	-5.504178,
	-5.502512,
	-5.502512,
	-5.500845,
	-5.500845,
	-5.500845,
	-5.499175,
	-5.497504,
	-5.495833,
	-5.495833,
	-5.495833,
	-5.494162,
	-5.492487,
	-5.490811,
	-5.489141,
	-5.487461,
	-5.487461,
	-5.485785,
	-5.48411,
	-5.48243,
	-5.48075,
	-5.47907,
	-5.477386,
	-5.475706,
	-5.475706,
	-5.474021,
	-5.472337,
	-5.470652,
	-5.468967,
	-5.46559,
	-5.4639,
	-5.462211,
	-5.460522,
	-5.458828,
	-5.457134,
	-5.453747,
	-5.452053,
	-5.450355,
	-5.448657,
	-5.446959,
	-5.443562,
	-5.441859,
	-5.440156,
	-5.43675,
	-5.43334,
	-5.431633,
	-5.428213,
	-5.426506,
	-5.423081,
	-5.42137,
	-5.417941,
	-5.414512,
	-5.411074,
	-5.409358,
	-5.405915,
	-5.402472,
	-5.399021,
	-5.395569,
	-5.392113,
	-5.388652,
	-5.386922,
	-5.383456,
	-5.379986,
	-5.376516,
	-5.373037,
	-5.369558,
	-5.366074,
	-5.36433,
	-5.360842,
	-5.355599,
	-5.352098,
	-5.348595,
	-5.345088,
	-5.339819,
	-5.334545,
	-5.331025,
	-5.327499,
	-5.323969,
	-5.318668,
	-5.315129,
	-5.309813,
	-5.306265,
	-5.300936,
	-5.297374,
	-5.292031,
	-5.288465,
	-5.283108,
	-5.277741,
	-5.274157,
	-5.268777,
	-5.263388,
	-5.259793,
	-5.25439,
	-5.248978,
	-5.245365,
	-5.23994,
	-5.232691,
	-5.22906,
	-5.223611,
	-5.218148,
	-5.21268,
	-5.207204,
	-5.201718,
	-5.196227,
	-5.190722,
	-5.185214,
	-5.179691,
	-5.174163,
	-5.168626,
	-5.161235,
	-5.155675,
	-5.148255,
	-5.142677,
	-5.137094,
	-5.129633,
	-5.124027,
	-5.116543,
	-5.10904,
	-5.101524,
	-5.095876,
	-5.088336,
	-5.080778,
	-5.073202,
	-5.067512,
	-5.059912,
	-5.052299,
	-5.044666,
	-5.03511,
	-5.027444,
	-5.019766,
	-5.012069,
	-5.004357,
	-4.996632,
	-4.988893,
	-4.981136,
	-4.971421,
	-4.961679,
	-4.95387,
	-4.946047,
	-4.936244,
	-4.928389,
	-4.918545,
	-4.910648,
	-4.902741,
	-4.892836,
	-4.882903,
	-4.872952,
	-4.862972,
	-4.854972,
	-4.844951,
	-4.832893,
	-4.824837,
	-4.814746,
	-4.804626,
	-4.794488,
	-4.784322,
	-4.774132,
	-4.761878,
	-4.751637,
	-4.741368,
	-4.731081,
	-4.718705,
	-4.706288,
	-4.695921,
	-4.683443,
	-4.673019,
	-4.66048,
	-4.647908,
	-4.633193,
	-4.620545,
	-4.605745,
	-4.590899,
	-4.57387,
	-4.561059,
	-4.546071,
	-4.52673,
	-4.509471,
	-4.492151,
	-4.47477,
	-4.457327,
	-4.437633,
	-4.417858,
	-4.398003,
	-4.378073,
	-4.358062,
	-4.335738,
	-4.315562,
	-4.290796,
	-4.268178,
	-4.245465,
	-4.224939,
	-4.197452,
	-4.172131,
	-4.146691,
	-4.118805,
	-4.095461,
	-4.06967,
	-4.041398,
	-4.010612,
	-3.984429,
	-3.955738,
	-3.924493,
	-3.893081,
	-3.861506,
	-3.827316,
	-3.797859,
	-3.768257,
	-3.736034,
	-3.701139,
	-3.666055,
	-3.633304,
	-3.597844,
	-3.562191,
	-3.526346,
	-3.490306,
	-3.456666,
	-3.420254,
	-3.383643,
	-3.346838,
	-3.309838,
	-3.272644,
	-3.232575,
	-3.194976,
	-3.154473,
	-3.113745,
	-3.080998,
	-3.045365,
	-3.009556,
	-2.970807,
	-2.934644,
	-2.898319,
	-2.861817,
	-2.82232,
	-2.791147,
	-2.75985,
	-2.728434,
	-2.694018,
	-2.665231,
	-2.633444,
	-2.601533,
	-2.572419,
	-2.546131,
	-2.516823,
	-2.496247,
	-2.472667,
	-2.449026,
	-2.42235,
	-2.404521,
	-2.386652,
	-2.368753,
	-2.35081,
	-2.335832,
	-2.320829,
	-2.308806,
	-2.299779,
	-2.290742,
	-2.281701,
	-2.275664,
	-2.266603,
	-2.260556,
	-2.257535,
	-2.254509,
	-2.251484,
	-2.248454,
	-2.248454,
	-2.248454,
	-2.251484,
	-2.251484,
	-2.254509,
	-2.257535,
	-2.260556,
	-2.266603,
	-2.269623,
	-2.278685,
	-2.284716,
	-2.293758,
	-2.299779,
	-2.308806,
	-2.317828,
	-2.326835,
	-2.335832,
	-2.344823,
	-2.353806,
	-2.368753,
	-2.380691,
	-2.392614,
	-2.404521,
	-2.416414,
	-2.431252,
	-2.443105,
	-2.457898,
	-2.469716,
	-2.484465,
	-2.499188,
	-2.513887,
	-2.525625,
	-2.540274,
	-2.554903,
	-2.569503,
	-2.584077,
	-2.598627,
	-2.613152,
	-2.627652,
	-2.642122,
	-2.653686,
	-2.668112,
	-2.685394,
	-2.699765,
	-2.711246,
	-2.725572,
	-2.739869,
	-2.754147,
	-2.765548,
	-2.77978,
	-2.793983,
	-2.80533,
	-2.816662,
	-2.827974,
	-2.839272,
	-2.850554,
	-2.859,
	-2.873065,
	-2.884298,
	-2.895517,
	-2.903918,
	-2.915107,
	-2.923485,
	-2.934644,
	-2.945789,
	-2.954136,
	-2.965252,
	-2.973579,
	-2.98467,
	-2.995741,
	-3.004035,
	-3.015076,
	-3.02335,
	-3.03161,
	-3.042616,
	-3.048108,
	-3.056347,
	-3.067311,
	-3.075526,
	-3.083736,
	-3.091931,
	-3.100117,
	-3.111022,
	-3.116469,
	-3.124625,
	-3.132777,
	-3.140923,
	-3.149055,
	-3.157182,
	-3.162591,
	-3.170702,
	-3.1788,
	-3.184198,
	-3.192282,
	-3.20036,
	-3.208428,
	-3.216486,
	-3.227215,
	-3.235254,
	-3.243284,
	-3.251303,
	-3.259313,
	-3.269979,
	-3.277969,
	-3.28595,
	-3.293925,
	-3.301886,
	-3.312488,
	-3.323076,
	-3.331007,
	-3.338925,
	-3.346838,
	-3.35474,
	-3.365264,
	-3.373147,
	-3.381021,
	-3.388885,
	-3.399356,
	-3.4072,
	-3.417647,
	-3.425467,
	-3.433282,
	-3.441083,
	-3.446282,
	-3.454073,
	-3.459263,
	-3.467035,
	-3.472214,
};

MainWindow::MainWindow(QWidget *parent) :
	QMainWindow(parent),
	ui(new Ui::MainWindow)
{
	ui->setupUi(this);
}

MainWindow::~MainWindow()
{
	delete ui;
}

void MainWindow::paintEvent(QPaintEvent *)
{
	QPainter painter(this);

	static const QColor frameCurveColor(210, 210, 210);

	QPolygonF polygon;

	QRect rect(QPoint(-36,-6), QPoint(757,0));

	qreal penWidth = rect.height() * 0.07;


	for ( int i = 0 ; i < 720; i++)
	{
		polygon.append(QPointF(i, y_list[i]));
	}



	painter.setBrush(QBrush(Qt::transparent, Qt::SolidPattern));
	painter.setPen(QPen(frameCurveColor, penWidth, Qt::DotLine));
	painter.drawLine(QPointF(0,0), QPointF(50, 50));
	painter.setWindow(rect);
	//polygon.translate(100, 100);
	painter.drawPolyline(polygon);

}


void MainWindow::on_pushButton_clicked()
{
	qDebug("run dlg");


	Dialog dlg(this);
	;

	connect(this, SIGNAL(signalMsg(QString)), &dlg, SLOT(slotMsg(QString)));

	dlg.show();

#if 0
	if ( dlg.exec() == QDialog::Accepted )
	{
		qDebug("dlg accepted");
	}
	else
	{
		qDebug("dlg rejected");
	}
#endif
}

void MainWindow::on_pushButton_signal_clicked()
{
	static int counter = 0;

	QString msg = QString("counter %1").arg(counter++);

	qDebug("emit signal : %s", msg.toAscii().constData());
	emit signalMsg(msg);
}
